<template>
  <div class="container">
    <h1 style="margin: 10px">关于我们</h1>
    专注于系统集成、IT运维，希望得到您的认可。谢谢~
  </div>
</template>

<script>
  // import 'babel-polyfill'
  // import {EventSourcePolyfill} from 'event-source-polyfill'

  export default {
    name: "about",
    layout: 'login_test',
    data() {
      return {
        evtSource:null
      }
    },
    watch: {},
    methods: {
      create () {
        let _this = this
        let token = ''
        if (this.$store.state.user.token) {
          //console.log("请求头加上token")
          token = 'Bearer ' + this.$store.state.user.token;
        }
        let url = 'http://localhost:3000/api/pings'
        this.evtSource = new EventSourcePolyfill(url, {
          headers: {Authorization:token}
        });
        console.log(this.evtSource)
        this.evtSource.onopen=function (event) {
          console.log('成功连接',event)
        };
        this.evtSource.addEventListener('open',function (e) {
          console.log('开始成功',e)
        })
        this.evtSource.addEventListener('message',e=>{
          console.log('eeee',e.data)
        });
        this.evtSource.addEventListener('error', event => {
                        // if (this.evtSource.readyState == EventSource.CLOSED) {
                           console.log('event was closed');
                           _this.evtSource.close();
                        // };
                    });
        this.evtSource.addEventListener('close', event => {
                        console.log(event.type);
                        console.log('close');
                        _this.evtSource.close();
                    });
      },
      stop(){
        this.evtSource.close();
        console.log('Connection closed');
      }
    },
  }
</script>

<style scoped>
  .container {
    text-align: center;
    padding: 20px;
  }
</style>
